﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web;
using System.Web.Http;
using System.Web.Script.Serialization;
using System.IO;
using System.Globalization;
using U9API.Pub;

namespace U9API
{
    public class ErrorResult : ActionResult
    {
        public ErrorResult(JsonModel.APIResponse result)
        {
            _result = result;
        }
        //private bool iserror = false;
        ///// <summary>
        ///// 是否产生错误
        ///// </summary>
        //public bool IsError
        //{
        //    get { return iserror; }
        //    set { this.iserror = value; }
        //}

        ///// <summary>
        ///// 错误信息，或者成功信息
        ///// </summary>
        //public string Message { get; set; }

        ///// <summary>
        ///// 成功可能时返回的数据
        ///// </summary>
        //public Object Data { get; set; }

        private JsonModel.APIResponse _result { get; set; }
        /// <summary>
        /// 正常序列化方式(为True则不进行UI友好的序列化)
        /// </summary>
        //public bool NotLigerUIFriendlySerialize { get; set; }
        public override void ExecuteResult(ControllerContext context)
        {

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = "application/json";

            StringWriter sw = new StringWriter();

            response.Write(_result.ToJson());

        }
    }
}